<?php

/**
 * Class CommonUtils
 * @author: Lee Way
 * @copyright: PiuZiu
 */
class CommonUtils {
	
	/**
	 * Check string start with other string or not.
	 *
	 * @param: $haystack
	 * @param: $needle
	 * @param: $case
	 *
	 * @return true or false;
	 */
	public static function startsWith($haystack,$needle,$case=true) {
		// in case: upper and lower case is the same
		if($case) {
			return (strcmp(substr($haystack, 0, strlen($needle)),$needle)===0);
		}
		// in case: upper and lower case is difference
		return (strcasecmp(substr($haystack, 0, strlen($needle)),$needle)===0);
	}

	/**
	 * Check string end with other string or not.
	 *
	 * @param: $haystack
	 * @param: $needle
	 * @param: $case
	 *
	 * @return true or false;
	 */
	public static function endsWith($haystack,$needle,$case=true) {
		// in case: upper and lower case is the same
		if($case){
			return (strcmp(substr($haystack, strlen($haystack) - strlen($needle)),$needle)===0);
		}
		// in case: upper and lower case is difference
		return (strcasecmp(substr($haystack, strlen($haystack) - strlen($needle)),$needle)===0);
	}
}

?>